package com.contract.controller;

import com.contract.pojo.input.UserQueryInput;
import com.contract.pojo.output.JsonResult;
import com.contract.pojo.output.PageOutput;
import com.contract.pojo.output.UserOutput;
import com.contract.service.SysUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户controller
 *
 * @author liw
 * @version 1.0
 * @date 2022/8/13 11:10
 */
@ApiOperation("用户")
@RestController
@RequestMapping("contract/user")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    @GetMapping("list")
    @ApiOperation("查询列表")
    @PreAuthorize("hasAuthority('user_list')")
    public JsonResult<PageOutput<UserOutput>> queryList(@RequestHeader("token") String token, UserQueryInput vo) {
        return sysUserService.queryList(vo);
    }

    @GetMapping("info/{id}")
    @ApiOperation("查询列表")
    @PreAuthorize("hasAuthority('user_info')")
    public JsonResult<UserOutput> queryInfo(@RequestHeader("token") String token, @PathVariable("id") Long id) {
        return sysUserService.queryInfo(id);
    }

    @DeleteMapping("info/{id}")
    @ApiOperation("查询列表")
    @PreAuthorize("hasAuthority('user_delete')")
    public JsonResult<Long> deleteUser(@RequestHeader("token") String token, @PathVariable("id") Long id) {
        return sysUserService.deleteUser(id);
    }

}
